package com.ryder.subject.domain.handler.subject;

import com.ryder.subject.common.enums.IsDeleteFlagEnum;
import com.ryder.subject.common.enums.SubjectInfoTypeEnum;
import com.ryder.subject.domain.convert.BriefSubjectConvert;
import com.ryder.subject.domain.entity.SubjectInfoBO;
import com.ryder.subject.domain.entity.SubjectOptionBO;
import com.ryder.subject.infra.basic.entity.SubjectBrief;
import com.ryder.subject.infra.basic.service.SubjectBriefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 描述: 简答题目的策略类
 *
 * @author Ryder
 * @version 1.0
 * @since 1.0 // 版本号，指明从哪个版本开始
 * 更新日期: 2025/02/05
 */

@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Autowired
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        //只处理BRIEF相关的
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        //简答题目的插入
        if (subjectInfoBO == null) {
            throw new RuntimeException("参数错误");
        }

        SubjectBrief subjectBrief = BriefSubjectConvert.INSTANCE.convertBoToBrief(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        subjectBrief.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());

        subjectBriefService.insert(subjectBrief);
    }

    @Override
    public SubjectOptionBO query(Long subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId(subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
